package epam.study.oop.stones.runner;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;
import epam.study.oop.stones.necklaces.Necklace;
import epam.study.oop.stones.necklaces.WorkOfNecklace;

public class Runner {
	private static Properties props = new Properties();
	private static int countStones;
	private static float minTransparency;
	private static float maxTransparency;

	private static void loadProperties() throws FileNotFoundException,
			IOException {
		props = new Properties();
		props.load(new FileInputStream("config.properties"));
		countStones = Integer.parseInt(props.getProperty("countStones"));
		minTransparency = Float
				.parseFloat(props.getProperty("minTransparency"));
		maxTransparency = Float
				.parseFloat(props.getProperty("maxTransparency"));
	}

	private static Logger log = Logger.getLogger(Runner.class.getName());

	public static void main(String[] args) throws FileNotFoundException,
			IOException, ClassNotFoundException {

		MyLogger.getLoggerConfiguration();
		log.log(Level.INFO,
				"************ NACHALO RABOTY C NECKLACE **************");

		// load the configurations
		loadProperties();

		Necklace my1 = new Necklace();
		my1 = WorkOfNecklace.generateNecklace(my1, countStones);

		// demonstrations of necklaces
		my1.showStones();

		WorkOfNecklace.SerializableOfObject(my1);

		// select stones for necklaces
		WorkOfNecklace.selectStonesForDelete(my1);
		my1.showStones();

		// sort of stones on the basis of value
		my1.sortByValueStones();
		my1.showStones();

		// search for stones of transparency
		Necklace my2 = WorkOfNecklace.seekRangeTransparency(my1,
				minTransparency, maxTransparency);
		my2.showStones();

		my1 = WorkOfNecklace.DeserializableOfObject(my1);
		my1.showStones();
		log.log(Level.INFO,
				"************ KONEC RABOTY C NECKLACE **************");
	}

}
